/* =============================================================================
 * decompose human capital into cohort and experience components
 * ===========================================================================*/


clear
use "temp\decomposition_h_cn.dta", clear
merge 1:1 year using "temp\decomposition_h_us.dta"
drop _m

tsset year
foreach v in wgt exp coh {
foreach c in cn us	{
	
	gen lnh_`v'_`c' = log(h_`v'_`c')
	gen lnh_`v'_`c'_norm = lnh_`v'_`c'[1]
	gen acc_lnh_`v'_`c' = lnh_`v'_`c' - lnh_`v'_`c'_norm
}
}

dis %9.0f acc_lnh_wgt_us[_N]*100
dis %9.0f acc_lnh_exp_us[_N]*100
dis %9.0f acc_lnh_coh_us[_N]*100
dis %9.0f acc_lnh_wgt_cn[_N]*100
dis %9.0f acc_lnh_exp_cn[_N]*100
dis %9.0f acc_lnh_coh_cn[_N]*100

twoway 	(scatter acc_lnh_wgt_us year, msymbol(o) msize(medium) connect(l) mcolor(blue) lcolor(blue))	///
		(scatter acc_lnh_exp_us year, msymbol(th) msize(medium) connect(l) lpattern(dash) mcolor(orange) lcolor(orange))	///
		(scatter acc_lnh_coh_us year, msymbol(dh) msize(medium) connect(l) lpattern(dash) mcolor(teal) lcolor(teal)),	///
		xlabel(1985(5)2012, labsize(medlarge))  ylabel(0(0.1)0.4, labsize(medlarge)) xtitle("Year", size(large)) 	///
		legend(order(1 "Human Capital" 2 "Experience" 3 "Cohort")	///
		rows(1) pos(6))		///
		title("U.S.", size(large) color(black)) name(us_hc,replace)

		
twoway 	(scatter acc_lnh_wgt_cn year, msymbol(o) msize(medium) connect(l) mcolor(blue) lcolor(blue))	///
		(scatter acc_lnh_exp_cn year, msymbol(th) msize(medium) connect(l) lpattern(dash) mcolor(orange) lcolor(orange))	///
		(scatter acc_lnh_coh_cn year, msymbol(dh) msize(medium) connect(l) lpattern(dash) mcolor(teal) lcolor(teal)),	///
		xlabel(1985(5)2012, labsize(medlarge))  ylabel(0(0.1)0.4, labsize(medlarge)) xtitle("Year", size(large)) 	///
		legend(order(1 "Human Capital" 2 "Experience" 3 "Cohort")	///
		rows(1) pos(6))		///
		title("China", size(large) color(black)) name(cn_hc,replace)
		
grc1leg us_hc cn_hc, name(hc_decomp, replace)
graph export "figures\hc_decomposition.pdf", as(pdf) replace

